<?php
namespace Api\Controller;
use Think\Controller;

class RegistController extends Controller
{
    public function regist()
    {

//            $username = I('post.username');
            $password = I('post.password');
//            $password1 = I('post.password1');
//            $name     = I('post.name');
            $phone    =I('post.phone');
            $cor      = I('post.corporate');
            $duty       = I('post.duty');
            $email      = I('post.email');
            $reg_time   =I('post.reg_time');
            $reg_source = I('post.source');
            $invite_code=I('post.invite_code');

        $user = M('UserList');
        $info = $user->where(array('username'=>$username))->find();
        if($info){
            $this->ajaxReturn(array('code' => 201, 'msg' => '账号已存在'),'json');
        }
        if($username==""){
            $this->ajaxReturn(array('code' => 201, 'msg' => '账号不能为空'),'json');
        }
        if($password==''||$password1==''){
            $this->ajaxReturn(array('code' => 201, 'msg' => '密码不能为空'),'json');
        }
        if($password!==$password1){
            $this->ajaxReturn(array('code' => 201, 'msg' => '两次密码输入不一致'),'json');
        }
        if($name==''){
            $this->ajaxReturn(array('code' => 201, 'msg' => '用户名不能为空'),'json');
        }
        //邮箱
        if (!preg_match("/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/",$email)) {
            $this->ajaxReturn(array('code' => 201, 'msg' => '邮箱格式不对！'),'json');
            }
        if($email==''){
            $this->ajaxReturn(array('code' => 201, 'msg' => '邮箱不能为空！'),'json');
        }
        if($phone==''){
            $this->ajaxReturn(array('code' => 201, 'msg' => '手机号不能为空！'),'json');
        }

        if (!preg_match("/^1[3,4,5,7,8]\d{9}$/",$phone)) {
            $this->ajaxReturn(array('code' => 201, 'msg' => '手机号格式不对！'),'json');
        }
        if($cor==''){
            $this->ajaxReturn(array('code' => 201, 'msg' => '注册公司不能为空！'),'json');
        }




       // $checkcode = I('post.checkcode');
        //检查验证码是否正确
        //$obj = new \Think\Verify();

//        if (!$obj->check($checkcode)) {
//            $this->ajaxReturn(array('status' => 0, 'msg' => '验证码错误'));
//        }

        //实例化模型对象 调用方法入库
        //$model = D('UserList');
        //$res = $model->regist($username);
        if (!$res) {
            $this->ajaxReturn(array('code' => 201, 'msg' => '注册失败'),'json');
        }
        $this->ajaxReturn(array('code' => 200, 'msg' => '注册成功'),'json');
    }


//    //生成验证码
//    public function code()
//    {
//        $obj = new \Think\Verify();
//        $obj->entry();
//    }



}